package com.cloud.salon.client.business.controller;

import com.cloud.salon.client.business.service.ItemService;
import com.cloud.salon.common.base.response.Res;
import com.cloud.salon.common.base.entity.business.Item;
import com.cloud.salon.common.base.vo.business.ItemLineVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 项目管理控制器
 * @Author wolf--LZH
 * @CreateDate 2019/4/10 0010 下午 1:30
 */
@RestController
@RequestMapping("item")
@Api(tags = "项目相关接口")
public class ItemController {

    private final String name = "项目";

    @Autowired
    private ItemService service;

    @PostMapping("findById")
    @ApiOperation(value="通过id查找一个" + name)
    public Res<Item> findById(@RequestBody Integer id) {
        return service.findById(id);
    }

    @PostMapping("findAll")
    @ApiOperation(value="获取所有的" + name)
    public Res<List<Item>> findAll() {
        return service.findAll();
    }

    @PostMapping("findByIdList")
    @ApiOperation(value="获取所有的" + name)
    public Res<List<Item>> findByIdList(@RequestBody List<Integer> idList) {
        return service.findByIdList(idList);
    }

    @PostMapping("findByRecord")
    @ApiOperation(value="通过记录获取对应的" + name)
    public Res<List<ItemLineVO>> findByRecord(@RequestBody Integer recordId) {
        return service.findByRecord(recordId);
    }

    @PostMapping("save")
    @ApiOperation(value="添加一个" + name)
    public Res<Item> save(@RequestBody Item item) {
        return service.save(item);
    }

    @PostMapping("saveAll")
    @ApiOperation(value="批量添加" + name)
    public Res<List<Item>> saveAll(@RequestBody List<Item> items) {
        return service.saveAll(items);
    }

    @PostMapping("update")
    @ApiOperation(value="修改" + name + "数据")
    public Res<Item> update(@RequestBody Item item) {
        return service.update(item);
    }

    @PostMapping("updateAll")
    @ApiOperation(value="批量修改" + name + "数据")
    public Res<List<Item>> updateAll(@RequestBody List<Item> items) {
        return service.updateAll(items);
    }

    @PostMapping("deleteById")
    @ApiOperation(value="通过id删除对应" + name)
    public Res<Boolean> deleteById(@RequestBody Integer id) {
        return  service.deleteById(id);
    }

    @PostMapping("deleteByIdAll")
    @ApiOperation(value="通过id集合批量删除" + name)
    public Res<Integer> deleteByIdAll(@RequestBody List<Integer> ids) {
        return service.deleteByIdAll(ids);
    }
}
